﻿@using LJD.App.Util
@model LJD.App.Model.DbModels.SysUserInfo

@{
    ViewData["Title"] = "编辑";
    Layout = "~/Views/Shared/_LayUIFormLayout.cshtml";
}

<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item layui-hide layui-col-md12">
        <label class="layui-form-label">ObjectId</label>
        <div class="layui-input-inline">
            <input type="text" name="ObjectID" placeholder="ObjectId" value="@Model.ObjectID" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md12">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="ULoginName" lay-verify="ULoginName" value="@Model.ULoginName" placeholder="请输入用户名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md12">
        <label class="layui-form-label">真实姓名</label>
        <div class="layui-input-block">
            <input type="text" name="URealName" lay-verify="URealName" value="@Model.URealName" placeholder="请输入真实姓名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md12">
        <label class="layui-form-label">电话</label>
        <div class="layui-input-block">
            <input type="text" name="UTelphone" lay-verify="UTelphone" value="@Model.UTelphone" placeholder="请输入电话" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md12">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-block">
            <input type="text" name="UMobile" lay-verify="required|phone" value="@Model.UMobile" placeholder="请输入手机号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md12">
        <label class="layui-form-label">Email</label>
        <div class="layui-input-block">
            <input type="text" name="UEmail" lay-verify="email" value="@Model.UEmail" placeholder="请输入Email" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md12">
        <label class="layui-form-label">QQ</label>
        <div class="layui-input-block">
            <input type="text" name="UQQ" lay-verify="UQQ" value="@Model.UQQ" placeholder="请输入QQ" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md12">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            @{
                if (Model.UGender.Equals((int)Gender.Man))
                {
                    <input type="radio" name="UGender" value="1" title="男" checked>
                    <input type="radio" name="UGender" value="0" title="女"> 
                }
                else
                {
                    <input type="radio" name="UGender" value="1" title="男">
                    <input type="radio" name="UGender" value="0" title="女" checked> 
                }
            }

        </div>
    </div>
    <div class="layui-form-item layui-col-md12">
        <label class="layui-form-label">所属部门</label>
        <div class="layui-input-block">
            <select name="UDepID" lay-verify="required" lay-search>
                <option value="">带搜索的选择框</option>
                <option value="1">layer</option>
                <option value="2">form</option>
                <option value="3">layim</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item layui-col-md12">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea name="Remark" lay-verify="required" autocomplete="off" class="layui-textarea">@Model.Remark</textarea>
        </div>
    </div>
    <div class="layui-form-item layui-col-md12">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            @if (Model.Status.Equals((int)Status.On))
            {
                <input type="checkbox" lay-filter="status" value="0" name="Status" lay-skin="switch" lay-text="启用|禁用" checked>
            }
            else
            {
                <input type="checkbox" lay-filter="status" value="0" name="Status" lay-skin="switch" lay-text="启用|禁用">
            }
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
    </div>
</div>


@section scripts
{
    <script type="text/javascript">
        layui.use(['form'],
            function() {
                var $ = layui.$, form = layui.form; 
                //监听提交
                form.on('submit(layuiadmin-app-form-submit)',
                    //注意：这里只是添加的用，编辑的在index页面
                    function(data) {
                        var field = data.field; //获取提交的字段 
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        debugger;
                        //提交 Ajax 成功后，关闭当前弹层并重载表格
                        $.ajax({
                            url: '@Url.Action("Form", "UserInfo")',
                            type: 'POST',
                            data: field,
                            dataType: 'json',
                            success: function(data) {
                                debugger;
                                if (data.Success) {
                                    parent.layui.table.reload('LAY-app-list'); //重载表格
                                    parent.layer.close(index); //再执行关闭
                                } else {
                                    layer.msg(data.Message, {icon: 5});
                                }
                            }
                        });
                    });
                /* 自定义验证规则 */
                form.verify({
                    ULoginName: function(value) {
                        if (value.length < 5||value.length>15||!/^[A-Za-z0-9]+$/.test(value)) {
                            return '用户名必须由英文或数字组成且长度为5-15';
                        }
                    },
                    URealName: function(value) {
                        if (value.length < 2) {
                            return '姓名至少2个汉字';
                        }
                        if (!/^[\u4e00-\u9fa5]{0,}$/.test(value)) {
                            return '姓名必须是汉字';
                        }
                    },
                    UTelphone: [/\d{3}-\d{8}|\d{4}-\d{7,8}/, '请输入正确的电话号码'],
                    Uqq: [/[1-9][0-9]{4,}/, '请输入正确的QQ号']

                });
            })
    </script>
}